package com.guchenbo.demo.jdbc.service;

import com.guchenbo.demo.jdbc.dao.mapper.User1Mapper;
import com.guchenbo.demo.jdbc.dao.pojo.User1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author guchenbo
 * @Date 2020/3/23.
 */
@Service
public class User1ServiceImpl implements User1Service {
    @Autowired
    private User1Mapper user1Mapper;

    @Override
    @Transactional
    public void addRequired(User1 user) {
        user1Mapper.insert(user);
    }


    @Override
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void addRequiredNew(User1 user) {
        user1Mapper.insert(user);
    }
    @Override
    @Transactional
    public void addRequiredException(User1 user) {
        user1Mapper.insert(user);
        throw new RuntimeException();
    }

    @Override
    @Transactional(propagation = Propagation.NESTED)
    public void addNested(User1 user) {
        user1Mapper.insert(user);

    }

    @Override
    @Transactional(propagation = Propagation.NESTED)
    public void addNestedException(User1 user) {
        user1Mapper.insert(user);
        throw new RuntimeException();

    }
}
